<?php
require_once("../../resources/commons.php");
require_once("../../data/User.php");
require_once("../../data/Item.php");

SessionManager::getInstance()->checkSession();
displayTop("Dashboard","../../resources/ajaxscripts.php",null);

/**
 * Display all the reportItems associated with this activity
 * @param Activity $p_record
 */
function displayAllReportItems($p_record){
	?>
	<a href="display_all_activity_reports.php?id=<?=base64_encode($p_record->getId()) ?>">Display all reports</a>
	<?php
}

/**
 * Display the form which allow to allocate an action to a user
 * @param Item $p_record
 */
function allocateAction($p_record){
	$l_allocatedUserId=$p_record->getAllocatedUser_id();
	if(isset($l_allocatedUserId)){
		$l_allocationLabel="Re-allocate";
	}else{
		$l_allocationLabel="Allocate";
	}
	?>
	<a href="allocate_action.php?id=<?=base64_encode($p_record->getId()) ?>"><?=$l_allocationLabel ?></a>
	<?php
}

/**
 * Display the form which allow to close an action
 * @param Item $p_record
 */
function closeAction($p_record){
	?>
	- <a href="close_action.php?id=<?=base64_encode($p_record->getId()) ?>">Close</a>
	<?php
}


/**
 * Display the form which allow to add a comment to an action
 * @param Item $p_record
 */
function addComment($p_record){
	?>
	- <a href="comment_action.php?id=<?=base64_encode($p_record->getId()) ?>">Comment</a>
	<?php
}


/**
 * Display the form which allow to update the description or title of an action
 * @param Item $p_record
 */
function updateAction($p_record){
	?>
	- <a href="update_action.php?id=<?=base64_encode($p_record->getId()) ?>">Update</a>
	<?php
}
?>

<h1>My personal activities</h1>
<?php
$l_user=User::getFromPrimaryKey(SessionManager::getCurrentLoggedUserId());
$l_activities=$l_user->getOpenActivities();

if(count($l_activities)!=0){
	$l_activitiesTable=new TableData("activitiesTable");
	$l_activitiesTable->addHeader("title","Title");
	$l_activitiesTable->addHeader("description","Description");
	$l_activitiesTable->addAction("displayAllReportItems");
	$l_activitiesTable->setRecords($l_activities);
	displayTable($l_activitiesTable);
}else{
	?>
	<div style="color: white;background-color: red;">No activity</div>
	<?php
}
?>

<h1>The actions I have been personally allocated</h1>
<p>The actions which you are allocated (= that you must complete).</p>

<?php
$l_records=$l_user->getOpenAllocatedActions();

if(count($l_records)!=0){
	$l_allocatedActionsTable=new TableData("AllocatedActionsTable");
	$l_allocatedActionsTable->addHeader("title","Action");
	$l_allocatedActionsTable->addHeader("activityLabel","Activity");
	$l_allocatedActionsTable->addHeader("overdueHtmlFlag","Overdue");
	$l_allocatedActionsTable->addHeader("commentCount","Comments");
	$l_allocatedActionsTable->addHeader("allocated","Allocated");
	$l_allocatedActionsTable->setRecords($l_records);
	$l_allocatedActionsTable->addAction("addComment");
	$l_allocatedActionsTable->setZoomArea("ajax_action_details.php");
	
	displayTable($l_allocatedActionsTable);
}else{
	?>
	<div style="color: white;background-color: red;">No actions</div>
	<?php
}
?>
<br/>
<h1>The actions I created</h1>
<p>The actions which you created.</p>
<?php
$l_records=$l_user->getOpenCreatedActions();

if(count($l_records)!=0){
	$l_createdActionsTable=new TableData("CreatedActionsTable");
	$l_createdActionsTable->addHeader("title","Action");
	$l_createdActionsTable->addHeader("activityLabel","Activity");
	$l_createdActionsTable->addHeader("overdueHtmlFlag","Overdue");
	$l_createdActionsTable->addHeader("commentCount","Comments");
	$l_createdActionsTable->addHeader("created","Created");
	$l_createdActionsTable->setRecords($l_records);
	$l_createdActionsTable->addAction("allocateAction");
	$l_createdActionsTable->addAction("closeAction");
	$l_createdActionsTable->addAction("addComment");
	$l_createdActionsTable->addAction("updateAction");
	$l_createdActionsTable->setZoomArea("ajax_action_details.php");
	
	displayTable($l_createdActionsTable);
}else{
	?>
	<div style="color: white;background-color: red;">No actions</div>
	<?php
}
displayBottom();
?>